<#escape x as (x)!?html>
    <#import "/page/Utils.ftl" as utils/>
    <#import "/page/synxisadapter/EnumUtils.ftl" as enumUtils/>
<head>
    <script type="text/javascript">
        var menuId = "Monitor_Reservation";

        $(function() {
            $("#afterDate,#beforeDate").datepicker(
                    $.extend({}, $.datepicker.regional[""],
                    {
                        beforeShow : function(input) {
                            return {
                                minDate: (input.id == "beforeDate" ? $("#afterDate").datepicker("getDate") : null),
                                maxDate: (input.id == "afterDate" ? $("#beforeDate").datepicker("getDate") : null)
                            };
                        },
                        dateFormat: "yy-mm-dd",
                        showOn: "both",
                        buttonImage: "${request.contextPath}/contrib/jquery/datepicker/calendar.gif",
                        buttonImageOnly: true
                    }));
        });

        function viewDetail(e) {
            var tr = e.parent().parent();
            var ersp = tr.find("input[@name='ersp']").val();

            $("#viewDetailForm").find("input[@name='ersp']").val(ersp);
            $("#viewDetailForm").submit();
        }

    </script>
</head>
<body>

<form id="viewDetailForm" method="GET" action="view.action" target="_blank">
    <input type="hidden" name="ersp"/>
</form>

<table>
    <caption>
        <div class="tools border">Query Reservations:
        </div>
    </caption>
</table>
<table>
    <caption>
        <div class="tools border">
            <form id="mainForm" action="query!query.action" method="GET">
                <input name="page" type="hidden"/>
                <input name="count" type="hidden"/>
                <table class="form_table">
                    <tr>
                        <td class="key">Status:&nbsp;</td>
                        <td class="value"><select class="select" name="condition.status">
                            <option value="">ALL</option>
                            <#list enumUtils.enumReservationStatus() as status>
                                <option value="${status}" ${(condition.status==status)?string("selected='selected'","")}>${status}</option>
                            </#list>
                        </select></td>
                        <td class="key">Range:</td>
                        <td class="value"><input id="afterDate" type="text" class="text" name="condition.after"
                                                 value="${condition.after?date}"></td>
                        <td class="key">----------</td>
                        <td class="value" colspan="3"><input id="beforeDate" type="text" class="text"
                                                             name="condition.before" value="${condition.before?date}">
                        </td>
                    </tr>
                    <tr>
                        <td class="key">ERSP:</td>
                        <td class="value" colspan="3"><input type="text" class="text"
                                                             name="condition.ersp" value="${condition.ersp?html}">
                        </td>
                        <td class="key">Res No.：</td>
                        <td class="value" colspan="3"><input type="text" class="text"
                                                             name="condition.resNumber" value="${condition.resNumber?html}">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="10" align="right"><input type="submit" value="Query" class="btn"></td>
                    </tr>
                </table>
            </form>
        </div>

    </caption>
    <thead>
    <tr>
        <th>CreateTime</th>
        <th>LastUpdateTime</th>
        <th>ERSP</th>
        <th>Hotel</th>
        <th>ResNo.</th>
        <th>CancelNo.</th>
        <th>Status</th>
        <th>Operation</th>
    </tr>
    </thead>
    <tbody>
        <#list reservations as reservation>
            <tr class="${(reservation_index%2==0)?string('even','odd')}">
            <td>${reservation.createTime?datetime}&nbsp;</td>
            <td>${reservation.lastUpdateTime?datetime}&nbsp;</td>
            <td>${reservation.ersp}<input type="hidden" name="ersp" value="${reservation.ersp}"/>&nbsp;</td>
            <td>${reservation.hotelId}</td>
            <td>
                <#list reservation.reservationItems as item>
                <span title="Confirm at ${item.confirmTime?datetime}">${item.confirmNumber}</span><br/>
                </#list>
            </td>
            <td>
                <#list reservation.reservationItems as item>
                <span title="Cancell at ${item.cancelTime?datetime}">${item.cancelNumber}</span><br/>
                </#list>
            </td>
            <td>${reservation.status}&nbsp;</td>
            <td><input type="button" value="Details" class="btn" onclick="viewDetail($(this))"/>&nbsp;</td>
        </tr>
        </#list>
    <tbody>
    <tfoot>
        <#if paginator?exists>
        <tr>
            <td colspan="100" class="tools">
                <div class="paginator">
                <@utils.paging paginator "navigate" 20/>
                    <script type="text/javascript">
                        function navigate(page, count) {
                            $("#mainForm > input[name='page']").val(page);
                            $("#mainForm > input[name='count']").val(count);
                            $("#mainForm").submit();
                        }
                    </script>
                </div>
                &nbsp;</td>
        </tr>
        </#if>
    </tfoot>
</table>
</body>
</#escape>